<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="" id="form">
        <input type="text">
        <input type="submit">
    </form>
    <script>
        const f = document.getElementById('form')
        f.addEventListener('submit', function (e) {
            e.preventDefault() // 阻止默认行为，不让 form 提交
            console.log(123);
        })
    </script>
</body>

</html>